{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c99ef4b0",
   "metadata": {},
   "source": [
    "----------------------  \n",
    "* 2022/10/10  \n",
    "* python学习记录  \n",
    "* 记录人：江柯廷  \n",
    "----------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1df7512",
   "metadata": {},
   "source": [
    "## 1.字符串（stant）  \n",
    "* 1.关于字符串的基本内容  \n",
    "* 2.关于字符串使用方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4d4a4e8",
   "metadata": {},
   "source": [
    "### 1.1 关于字符串的基本内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0f346937",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'span eggs'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'span eggs'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a0e6c338",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(type('span eggs'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "961a0691",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(type('span eggs'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "06023b21",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (3578565646.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [4]\u001b[1;36m\u001b[0m\n\u001b[1;33m    'doesn't'\u001b[0m\n\u001b[1;37m           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "'doesn't'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0c46f9e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 以上解决方法\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0826702c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8119ac86",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三引号：保留字符串信息的 格式信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8ed7f1ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''doesn't'''"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "143bcf41",
   "metadata": {},
   "source": [
    "### 1.2  关于字符串的方法及函数  \n",
    "> 1. 字符串是可以拼接的（字符串的运算），用 + 进行字符串之间的拼接  \n",
    "> 2. 字符串是有顺序的,从第一个字符开始，从0依次往后，有长度,可以用len()检查字符串的长度  \n",
    "> 3. 字符串的取值  \n",
    ">> 1. 取单个值：从左往右（正数，第一个值是0），从右往左（负数，第一个值是-1）  \n",
    ">> 2. 取多个值：切片的方法，两个值作为 取值的区间  \n",
    "> 4. 字符串的方法及函数  \n",
    ">> 1. in 查询成员是否存在  \n",
    ">> 2. str.count()查询数量  \n",
    ">> 3. str.isdigit()判断字符串是否是 数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0d69887d",
   "metadata": {},
   "outputs": [],
   "source": [
    "nev_name = [\"小明\",\"小红\",\"张杰\",\"李华\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "054bece8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院团委欢迎小明\n",
      "广州南方学院团委欢迎小红\n",
      "广州南方学院团委欢迎张杰\n",
      "广州南方学院团委欢迎李华\n"
     ]
    }
   ],
   "source": [
    "for i in nev_name:\n",
    "    print(\"广州南方学院团委欢迎\"+i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3256a999",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委欢迎小明'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州南方学院团委欢迎\"+\"小明\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7dc27301",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委欢迎小明'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = '广州南方学院团委欢迎小明'\n",
    "text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e0587076",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c0ef787c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4537c7cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d8eca0f0",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [21]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtext\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m12\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    "text[12]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "0d637d57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "e853c0a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[6]+text[7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "9fce763d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用 切片 的方法进行多个值取值\n",
    "text[6:8]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bcfbc130",
   "metadata": {},
   "source": [
    "* in 查询成员"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "4109adf5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'广州' in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "e4da00b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'北京' in text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "89512b6f",
   "metadata": {},
   "source": [
    "*  str.count()查询数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "0c925bb9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text.count('广州')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9bf917f0",
   "metadata": {},
   "source": [
    "* str.isdigit()判断字符串是否是 数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "3f23a83f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "age_li = 19\n",
    "age_wang = '19'\n",
    "print(age_li,type(age_li))\n",
    "print(age_wang,type(age_wang))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "0920f81e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_wang.isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "9bf3a5fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text .isdigit()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ad2e872",
   "metadata": {},
   "source": [
    "## 2. 有序的列表——列表（list）  \n",
    "> 1. 列表的基本运算法则（参考：有序的数据结构的运算法则列表）  \n",
    "> 2. 列表的一般方法（要求：全部掌握，并且做总结在课后笔记中）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "c74af405",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考： 假设，有这样一个场景，我要存放/录入一个班的同学的信息（名单信息），用字符串存放是否可行？如何取值呢？\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "63f086e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串存放\n",
    "网二_name = \"李华，小明，李晓华，张强\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "1fe76feb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串取值,比较麻烦\n",
    "网二_name[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "7dc8aba2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小明'"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name[3:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a640e093",
   "metadata": {},
   "source": [
    "* 对比字符串和列表  \n",
    "> 1. 字符串是按照字符进行数值取值  \n",
    "> 2. 列表是按照元素进行数据取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "ae64a859",
   "metadata": {},
   "outputs": [],
   "source": [
    "网二_name_list = [\"李华\",\"小明\",\"李晓华\",\"小红\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "3c5fa8af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(网二_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "a111b8a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "0599a1ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李晓华', '小红']"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name_list[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "62e27090",
   "metadata": {},
   "outputs": [],
   "source": [
    "网二_age_list = [19,20,19,22]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "db252c23",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_age_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "bea3daba",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[19, 20, 19, 22]"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_age_list[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "1c62a79d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_age_list.count(19)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca3270a9",
   "metadata": {},
   "source": [
    "### 2.2 列表的方法  \n",
    "> 1. 增加  \n",
    "> 2. 删除  \n",
    "> 3. 修改  \n",
    "> 4. 查询in,count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "6af6bc2e",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jake\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "934bf9a9",
   "metadata": {},
   "source": [
    "* 学习方法  \n",
    "> 1. listname.Tab键 查看所有方法名称  \n",
    "> 2. help(listname.function)查看其中一个方法的具体操作内容  \n",
    "  \n",
    "> 课后练习（做一个表格，总结列表的方法）：  \n",
    "\n",
    "| 列表方法       | Description | example    |  \n",
    "| ----------------- | ----------- | ----------- |  \n",
    "| append() 增加元素，增加在列表的末尾 | names.append(\"zhichao\"),"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8544d37f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 学习方法.Tab键  \n",
    "names."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "b8990501",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "582401e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"zhichao\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "efa580d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jake', 'zhichao']"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "2db69657",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'Alex' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [69]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m names\u001b[38;5;241m.\u001b[39minsert(\u001b[38;5;241m1\u001b[39m,\u001b[43mAlex\u001b[49m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'Alex' is not defined"
     ]
    }
   ],
   "source": [
    "names.insert(1,Alex)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
